import pymysql
class MysqlUtil:
    def __init__(self,host,):
        #连接
        self.conn = pymysql.connect()
        #自动提交
        self.conn.autocommit(True)
        #获取游标对象
        self.cursor = self.conn.cursor()

    def query(self,sql):
        self.cursor.execute(sql)
        #返回查询所有数据
        return self.cursor.fetchall()

    def update(self,sql,parmrs=None):
        try:
            self.cursor.execute(sql,parmrs)
            self.conn.commit()
        except Exception as result:
            print(result)
            #回滚
            self.conn.rollback()
        #关闭
    def close(self):
        #关闭游标
        self.cursor.close()
        #关闭连接
        self.conn.close()




if __name__ == '__main__':
    host=''
    qu = MysqlUtil(host)
    sql = ''
    print(qu.query(sql))